class Movie < ActiveRecord::Base
  SHOW_STATUS = [
      [ "on",  "on"],
        [ "off", "off"]
        ]
        validates_inclusion_of :show_status, :in => SHOW_STATUS.map{|disp,value|value}
  has_many :replies
  has_many :movie_pics
  has_many :recent_replies, :class_name => "Reply", :order => "created_at DESC", :limit => 10
  
  
  validates_presence_of :name, :movie_genre, :show_status, :cost
  validates_numericality_of :cost
  
  def self.find_on_show_movies
    find(:all, :conditions => "show_time > '#{Time.now.at_beginning_of_day.to_s(:db)}' and show_time < '#{Time.now.tomorrow.at_beginning_of_day.to_s(:db)}'")
  end
  
  def self.find_comming_soon_movies
    find(:all, :conditions => "show_time > '#{Time.now.tomorrow.at_beginning_of_day.to_s(:db)}'")
  end
  
  protected
  
  def validate
    # errors.add(:cost, "should be at least 0.01") if cost.nil? || cost < 0.01
    # errors.add(:ticket_price, "should be at least 0.01") if ticket_price.nil? || ticket_price < 0.01    # 
        # errors.add(:sale_amount, "should be at least 0.01") if sale_amount.nil? || sale_amount < 0.01
  end
end
